$(document).ready(function () {

    $('#pop-wrapper select').select0();

    $('#pop-wrapper .x-4-move').dragging({
        move: 'both',
        randomPosition: false,
        handler: '.panel-heading'
    });

    /*保存*/
    $('#pop-wrapper .btn-4-save').off('click').on('click', function () {
        var id = $('#pop-wrapper input[name=id]').val();
        var url = 'phase/add.htm';
        if (id) {
            url = 'phase/modify.htm';
        }
        ajaxSubmitResponseJSON({
            url: url,
            method: 'POST',
            data: $('#pop-wrapper form').serialize(),
            success: function (data) {
                if (data.status == 0) {
                    closeLayer();
                    $('#data-wrapper .btn-4-query').click();
                }
            }
        });
    });

    $('#pop-wrapper select.categoryLv1').off('change').on('change', function () {
        var categoryLv1Id = $(this).val();
        var htm = '<option value="">-请选择-</option>';
        if (!categoryLv1Id) {
            $('#pop-wrapper select[name=categoryId]').html(htm);
            $('#pop-wrapper select[name=categoryId]').select0();
            return;
        }
        ajaxSubmitResponseJSON({
            url: 'category/ajaxLevelTwoListByPid.htm/' + categoryLv1Id,
            success: function (data) {
                if (data.status == 0) {
                    var rowData = data.data;
                    if (rowData && rowData.length > 0) {
                        for (var i = 0; i < rowData.length; i++) {
                            htm += '<option value="' + rowData[i].id + '">' + rowData[i].name + '</option>';
                        }
                    }
                    $('#pop-wrapper select[name=categoryId]').html(htm);
                    $('#pop-wrapper select[name=categoryId]').select0();
                }
            }
        });
    });
});